package com.one.controller;

import com.one.bean.Activity;
import com.one.bean.Category;
import com.one.bean.Product;
import com.one.service.IndexService;
import com.one.util.RequestReturn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: tzy
 * @create: 2022/1/20
 * @FileName: IndexController
 * @Description: 主页展示操作入口
 */
@Slf4j
@Api(tags = "B.首页展示操作")
@RestController
public class IndexController {
    @Autowired
    private IndexService indexService;

    /**
     * @author: tzy
     * @date: 2022/1/20
     * @return: com.one.util.RequestResult<java.lang.String>
     * @Description: 查询指定分类的热销商品展示
     */
    @ApiImplicitParam(name = "categoryFirst", value = "一级分类id")
    @ApiOperation(value = "查询指定分类的热销商品展示", notes = "根据传入的一级分类id，查询热销商品")
    @GetMapping("/hotProducts")
    public RequestReturn<List<Product>> queryHotProducts(@RequestParam("categoryFirst") Integer categoryFirst){
        return indexService.queryHotProducts(categoryFirst);
    }


    /**
     * @author: tzy
     * @date: 2022/1/20
     * @return: com.one.util.RequestReturn<java.util.List<com.one.bean.Category>>
     * @Description: 根据商品一级分类，查询一二级分类的名称
     */
    @ApiOperation(value = "查询分类名称", notes = "可以根据一级分类id查询其二级分类的名称")
    @ApiImplicitParam(name = "categoryFirst", value = "一级分类id")
    @GetMapping("/categories")
    public RequestReturn<List<Category>> queryCategories(@RequestParam("categoryFirst") Integer categoryFirst){
        return indexService.queryCategories(categoryFirst);
    }

    /**
     * @author: tzy
     * @date: 2022/1/20
     * @return: com.one.util.RequestReturn<java.util.List<com.one.bean.Product>>
     * @Description: 查询商品对应分类的新品展示
     */
    @ApiOperation(value = "查询指定分类的新品展示", notes = "可以根据指定一级分类的id查询最新上架的商品展示")
    @ApiImplicitParam(name = "categoryFirst", value = "一级分类id")
    @GetMapping("/homePage/products")
    public RequestReturn<List<Product>> queryNewProducts(@RequestParam("categoryFirst") Integer categoryFirst){
        return indexService.queryNewProducts(categoryFirst);
    }

    /**
     * @author: tzy
     * @date: 2022/1/20
     * @return: com.one.util.RequestReturn<java.util.List<com.one.bean.Activity>>
     * @Description: 首页限时，秒杀，热销等活动网址跳转
     */
    @ApiOperation(value = "首页限时，秒杀，热销等活动网址跳转", notes = "查询出有效活动的详情列表")
    @GetMapping("/moduleToJump")
    public RequestReturn<List<Activity>> queryActivities(){
        return indexService.queryActivities();
    }

}
